﻿#include "T_TemplateDefinedWidget.h"
#include <iostream>
#include <QHBoxLayout>
#include <QIcon>
#include <QVBoxLayout>
#include <QLabel>
#include "ElaPushButton.h"
#include "ElaToolButton.h"
#include "ElaLineEdit.h"
#include "ElaComboBox.h"
#include "ElaScrollArea.h"
#include "ElaScrollPageArea.h"
#include "ElaImageCard.h"
#include "ElaStatusBar.h"
#include "ElaText.h"
#include "GenerateReportBase.h"
#include "FinalReportData.h"//tempuse
#include "MainWindow.h"
#include "BaseModule/GlobalHelper.h"
#include "CreateNewReport.h"
using namespace std;
namespace GenerateReport
{
    T_TemplateDefinedWidget::T_TemplateDefinedWidget(QWidget* parent)
        : ElaWidget(parent)
    {
        setWindowTitle(QStringLiteral("模板定义"));
        setWindowIcon(QIcon(":/QUI/image/GenerateReport_TemplateDefined1x.png"));
        //setStyleSheet("QWidget { qproperty - windowTitleFontSize: 14px; }");
        this->setIsFixedSize(true);
        setWindowModality(Qt::ApplicationModal);
        setWindowButtonFlags(ElaAppBarType::CloseButtonHint);

        updataUI();
    }

    T_TemplateDefinedWidget::~T_TemplateDefinedWidget()
    {
        if (m_templateCallComboBox)
        {
            delete m_templateCallComboBox;
            m_templateCallComboBox = nullptr;
        }
    }

    void T_TemplateDefinedWidget::updataUI()
    {
        //总布局（纵）
        QVBoxLayout* mainLayout = new QVBoxLayout(this);

        //第一行布局（横）
        QHBoxLayout* firstRowLayout = new QHBoxLayout;

        //第三行布局（横）
        QHBoxLayout* thirdRowLayout = new QHBoxLayout;

        //第一行内容：报告选择ReportTemplateSelection
        ElaText* _reportTemplateSelectionText = new ElaText(QStringLiteral("报告选择:"), this);
        _reportTemplateSelectionText->setWordWrap(false);
        _reportTemplateSelectionText->setTextPixelSize(14);
        m_templateCallComboBox = new ElaComboBox(this);
        QStringList _templateCallComboList
        {
            "无",
            //"模板1",
        };

        //tempuse
        auto _FinalReportData = FinalReportDataInstance->getFinalReportTotalData();
        for (auto _sigleReport : _FinalReportData)
        {
            _templateCallComboList << _sigleReport.at(0);
        }
        m_templateCallComboBox->setFixedWidth(250);
        m_templateCallComboBox->addItems(_templateCallComboList);

        //新建模板按钮
        ElaToolButton* _createNewTemplateButton = new ElaToolButton(this);
        _createNewTemplateButton->setIcon(QIcon(":/QUI/image/GenerateReport_plus.png"));
        _createNewTemplateButton->setFixedWidth(20);
        //编辑模板按钮
        ElaToolButton* _editTemplateButton = new ElaToolButton(this);
        _editTemplateButton->setIcon(QIcon(":/QUI/image/GenerateReport_edit.png"));
        _editTemplateButton->setFixedWidth(20);

        firstRowLayout->addWidget(_reportTemplateSelectionText);
        firstRowLayout->addWidget(m_templateCallComboBox);
        firstRowLayout->addWidget(_createNewTemplateButton);
        firstRowLayout->addWidget(_editTemplateButton);
        firstRowLayout->setAlignment(Qt::AlignLeft);
        firstRowLayout->setSpacing(2);

        //第二行内容：模板目录展示
        QWidget* arWidget = new QWidget; // 创建滚动显示区域幕布
        arWidget->setFixedSize(QSize(350,300));
        QVBoxLayout* vlayout = new QVBoxLayout(arWidget); // 创建布局, 用于将控件嵌入幕布中
        ElaText* _templateDirectoryText = new ElaText(QStringLiteral("1.扩大内需，既是应对外部冲击\n2.稳定经济运行的有效途径\n3.也是增强发展主动性的长久之策\n4.中央经济工作会议作出一系列安排\n5.加力扩围实施“两新”政策\n6.扩大服务消费\n7.促进文化旅游业发展\n8.积极发展首发经济\n9.冰雪经济\n10.银发经济\n11.大力实施城市更"), this);
        _templateDirectoryText->setTextPixelSize(15);
        vlayout->addWidget(_templateDirectoryText);

        auto variableArea = new ElaScrollArea(this);//滚动条
        variableArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);   //设置垂直滚动条
        variableArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);   //设置水平滚动条
        variableArea->setWidget(arWidget);

        //第三行内容：确定、取消按钮
        ElaPushButton* cancelButton = new ElaPushButton(QStringLiteral("取消"), this);
        cancelButton->setFixedWidth(80);
        ElaPushButton* confirmButton = new ElaPushButton(QStringLiteral("确定"), this);
        confirmButton->setFixedWidth(80);
        thirdRowLayout->addWidget(cancelButton);
        thirdRowLayout->addWidget(confirmButton);
        thirdRowLayout->setAlignment(Qt::AlignRight);
        thirdRowLayout->setSpacing(2);

        //总体布局
        //mainLayout->setContentsMargins(0, 0, 0, 0);
        mainLayout->addLayout(firstRowLayout);
        mainLayout->addWidget(variableArea);
        mainLayout->addLayout(thirdRowLayout);
        //mainLayout->setSpacing(20);

        //接口
        connect(_createNewTemplateButton, &ElaPushButton::clicked, this, &T_TemplateDefinedWidget::slot_createNewTemplateButtonClicked);

        connect(_editTemplateButton, &ElaPushButton::clicked, this, &T_TemplateDefinedWidget::slot_editTemplateButtonClicked);

        connect(cancelButton, &ElaPushButton::clicked, this, &T_TemplateDefinedWidget::slot_cancelButtonClicked);

        connect(confirmButton, &ElaPushButton::clicked, this, &T_TemplateDefinedWidget::slot_confirmButtonClicked);
    }

    void T_TemplateDefinedWidget::slot_cancelButtonClicked()
    {
        //关闭窗口
        ElaWidget::close();
    }

    void T_TemplateDefinedWidget::slot_confirmButtonClicked()
    {
        ElaWidget::close();
    }
    void T_TemplateDefinedWidget::slot_createNewTemplateButtonClicked()
    {

    }
    void T_TemplateDefinedWidget::slot_editTemplateButtonClicked()
    {

    }

    void T_TemplateDefinedWidget::setErrorMessagePrompt(QString errorMessage)
    {
        
    }
}
